<?php

namespace backend\modules\logs\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use backend\modules\logs\models\Unionpay3002SetLog;

/**
 * Unionpay3002SetLogSearch represents the model behind the search form about `backend\modules\logs\models\Unionpay3002SetLog`.
 */
class Unionpay3002SetLogSearch extends Unionpay3002SetLog
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id', 'p_at', 'r_at', 'last_get_time'], 'integer'],
            [['order_id', 'u_name', 'id_card', 'p_data', 'r_data', 'device_name'], 'safe'],
            [['score'], 'number'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = Unionpay3002SetLog::find()->orderBy(['id'=>SORT_DESC]);

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        $query->andFilterWhere([
            'id' => $this->id,
            'p_at' => $this->p_at,
            'r_at' => $this->r_at,
            'score' => $this->score,
            'last_get_time' => $this->last_get_time,
        ]);

        $query->andFilterWhere(['like', 'order_id', $this->order_id])
            ->andFilterWhere(['like', 'u_name', $this->u_name])
            ->andFilterWhere(['like', 'id_card', $this->id_card])
            ->andFilterWhere(['like', 'p_data', $this->p_data])
            ->andFilterWhere(['like', 'r_data', $this->r_data]);

        return $dataProvider;
    }
}
